home *** CD-ROM | disk | FTP | other *** search
/ Champak 49 / Volume 49 - JOGO DISK .iso / Games / hungerstrike.swf / scripts / __Packages / actionscript / Weapon.as < prev   
Encoding:
Text File  |  2007-09-28  |  10.9 KB  |  354 lines

  1. class actionscript.Weapon extends MovieClip
  2. {
  3.    var game;
  4.    var _bulletSpeed;
  5.    var _wLevel;
  6.    var _enemyDetected;
  7.    var _canBePlaced;
  8.    var _SellUpgrade;
  9.    var _type;
  10.    var w_mc;
  11.    var radius;
  12.    var _sdTime;
  13.    var _sdMult;
  14.    var _damage;
  15.    var _upgradeCost;
  16.    var _value;
  17.    var _sellingValue;
  18.    var _delay;
  19.    var _range;
  20.    var rangeCircle;
  21.    var _wCounter;
  22.    var bullet_mc;
  23.    var wInterval;
  24.    var _info;
  25.    var _drag;
  26.    var weapon;
  27.    var cross;
  28.    function Weapon()
  29.    {
  30.       super();
  31.       this.game = this._parent;
  32.       this._bulletSpeed = 700;
  33.       this._wLevel = 1;
  34.       this._enemyDetected = false;
  35.       this._canBePlaced = false;
  36.       this._SellUpgrade = false;
  37.       this.updateWeapon(this._type);
  38.       this.updateInfo();
  39.       this.game.currentWeapon = this;
  40.       this.w_mc.numbers._visible = false;
  41.       this.radius.setMask(this.game.gameMask_mc);
  42.       this.radius._visible = false;
  43.       this.gotoAndStop(this._type);
  44.    }
  45.    function updateWeapon(sType)
  46.    {
  47.       if(sType == "Pepsi")
  48.       {
  49.          this._sdTime = this.game.sdTime[sType + this._wLevel];
  50.          this._sdMult = this.game.sdMult[sType + this._wLevel];
  51.       }
  52.       this._damage = this.game.damage[sType + this._wLevel];
  53.       this._upgradeCost = this.game.upgradeCost[sType + this._wLevel];
  54.       this._value = this.game.wValue[sType + this._wLevel];
  55.       this._sellingValue = Math.floor(this._value / 100 * 75);
  56.       this._delay = this.game.delay[sType + this._wLevel];
  57.       this._range = this.game.range[sType + this._wLevel];
  58.       this.rangeCircle._radius = this._range / 2;
  59.       this.radius._xscale = this.radius._yscale = this._range;
  60.    }
  61.    function upgradeWeapon()
  62.    {
  63.       if(this._wLevel >= 3)
  64.       {
  65.          return undefined;
  66.       }
  67.       this._wLevel = this._wLevel + 1;
  68.       this.w_mc.numbers.gotoAndStop(this._wLevel);
  69.       this.updateWeapon(this._type);
  70.       this.clearWInterval();
  71.       this.updateInfo();
  72.       this.game.interface_mc.checkButtons();
  73.    }
  74.    function sellWeapon()
  75.    {
  76.       this.game.interface_mc.addSubtractMoney(this._sellingValue);
  77.       this.game.interface_mc.closeWeaponOptions(this);
  78.       this.removeWeapon();
  79.    }
  80.    function removeWeapon()
  81.    {
  82.       this.game.trail_mc["WeaponHitArea" + this._wCounter].removeMovieClip();
  83.       this.removeMovieClip();
  84.    }
  85.    function circlesColliding(cCircle1, cCircle2)
  86.    {
  87.       var _loc7_ = cCircle1._xCenter;
  88.       var _loc5_ = cCircle1._yCenter;
  89.       var _loc10_ = cCircle1._radius;
  90.       var _loc6_ = cCircle2._xCenter;
  91.       var _loc3_ = cCircle2._yCenter;
  92.       var _loc9_ = cCircle2._radius;
  93.       var _loc2_ = this.calcDistance(_loc7_,_loc5_,_loc6_,_loc3_);
  94.       if(_loc2_ <= _loc10_ + _loc9_)
  95.       {
  96.          return true;
  97.       }
  98.       return false;
  99.    }
  100.    function calcDistance(p1x, p1y, p2x, p2y)
  101.    {
  102.       var _loc2_ = Math.abs(p1x - p2x);
  103.       var _loc1_ = Math.abs(p1y - p2y);
  104.       var _loc3_ = Math.sqrt(_loc2_ * _loc2_ + _loc1_ * _loc1_);
  105.       return _loc3_;
  106.    }
  107.    function shoot(nx, ny, t_mc)
  108.    {
  109.       var _loc9_ = undefined;
  110.       var _loc7_ = undefined;
  111.       var _loc5_ = undefined;
  112.       var _loc10_ = undefined;
  113.       var _loc3_ = undefined;
  114.       var _loc4_ = undefined;
  115.       var _loc12_ = undefined;
  116.       var _loc2_ = undefined;
  117.       var _loc6_ = undefined;
  118.       var _loc11_ = nx + this._x;
  119.       var _loc8_ = ny + this._y;
  120.       _loc7_ = Math.abs(_loc11_ - this._x);
  121.       _loc5_ = Math.abs(_loc8_ - this._y);
  122.       _loc12_ = Math.atan(_loc5_ / _loc7_);
  123.       _loc2_ = _loc12_ * 180 / 3.141592653589793;
  124.       _loc9_ = Math.sqrt(_loc7_ * _loc7_ + _loc5_ * _loc5_);
  125.       _loc10_ = 20;
  126.       _loc3_ = _loc10_ * _loc7_ / _loc9_;
  127.       _loc4_ = _loc10_ * _loc5_ / _loc9_;
  128.       if(_loc11_ <= this._x)
  129.       {
  130.          if(_loc8_ <= this._y)
  131.          {
  132.             _loc6_ = 1;
  133.             _loc3_ = - _loc3_;
  134.             _loc4_ = - _loc4_;
  135.          }
  136.          else
  137.          {
  138.             _loc6_ = 4;
  139.             _loc3_ = - _loc3_;
  140.             _loc2_ = 360 - _loc2_;
  141.          }
  142.       }
  143.       else if(_loc8_ <= this._y)
  144.       {
  145.          _loc6_ = 2;
  146.          _loc4_ = - _loc4_;
  147.          _loc2_ = 180 - _loc2_;
  148.       }
  149.       else
  150.       {
  151.          _loc6_ = 3;
  152.          _loc2_ += 180;
  153.       }
  154.       this.bullet_mc = this.attachMovie("Bullet","Bullet",this.getNextHighestDepth(),{_damage:this._damage,_type:this._type,_speedX:_loc3_,_speedY:_loc4_,_targetX:nx,_targetY:ny,_rotation:_loc2_,_distance:_loc9_,_wLevel:this._wLevel,_q:_loc6_,tMc:t_mc});
  155.       if(this.wInterval == undefined)
  156.       {
  157.          this.waitTimer(this._delay,this);
  158.       }
  159.    }
  160.    function waitTimer(nDelay, mMc)
  161.    {
  162.       function test()
  163.       {
  164.          if(mMc._enemyDetected)
  165.          {
  166.             mMc._enemyDetected = false;
  167.          }
  168.          else
  169.          {
  170.             mMc.clearWInterval();
  171.          }
  172.       }
  173.       if(this.game._stopped)
  174.       {
  175.          return undefined;
  176.       }
  177.       var _loc2_ = this._delay * 1000;
  178.       this.wInterval = setInterval(test,_loc2_);
  179.    }
  180.    function clearWInterval()
  181.    {
  182.       clearInterval(this.wInterval);
  183.       this.wInterval = undefined;
  184.       this._enemyDetected = false;
  185.    }
  186.    function updateInfo()
  187.    {
  188.       this._info = this._type + ":<br><br> Weapon Level: " + this._wLevel + "<br> Damage: " + this._damage + "<br> Range: " + this._range / 10 + "<br> Rate: " + this._delay + " second(s)" + "<br> Sell for: " + this._sellingValue + " credit(s)";
  189.       if(this._upgradeCost != undefined)
  190.       {
  191.          this._info += "<br> Upgrade cost: " + this._upgradeCost + " credits";
  192.       }
  193.       else
  194.       {
  195.          this._info += "<br> Upgrade cost: Max Level Reached";
  196.       }
  197.       if(this._type == "Pepsi")
  198.       {
  199.          this._info += "<br>Reduce speed by: " + (100 - this._sdMult * 100) + "%<br> Duration:" + this._sdTime + " seconds";
  200.       }
  201.    }
  202.    function onEnterFrame()
  203.    {
  204.       if(this.game._stopped)
  205.       {
  206.          return undefined;
  207.       }
  208.       if(this._drag)
  209.       {
  210.          if(!this.weapon.hitTest(this.game.interface_mc) && !this.radius._visible && this._drag)
  211.          {
  212.             this.radius._visible = true;
  213.          }
  214.          if(this.weapon.hitTest(this.game.interface_mc) && this.radius._visible && this._drag)
  215.          {
  216.             this.radius._visible = false;
  217.          }
  218.          if(!this.game.trail_mc.isColliding(this.cross) && !this._canBePlaced)
  219.          {
  220.             var _loc9_ = this.game.interface_mc;
  221.             var _loc10_ = this.game.textMessages;
  222.             _loc9_.setText(_loc9_.info_txt,_loc10_._wCanBePlaced);
  223.             this.radius._xscale = this.radius._yscale = this._range;
  224.             this.radius.setMask(this.game.gameMask_mc);
  225.             this._canBePlaced = true;
  226.             this.w_mc.numbers._visible = false;
  227.             ┬º┬ºpush(this.gotoAndStop(this._type));
  228.          }
  229.          if(this.game.trail_mc.isColliding(this.weapon) && this._canBePlaced)
  230.          {
  231.             _loc9_ = this.game.interface_mc;
  232.             _loc10_ = this.game.textMessages;
  233.             _loc9_.setText(_loc9_.info_txt,_loc10_._wCannotBePlaced);
  234.             this.radius._xscale = this.radius._yscale = this._range;
  235.             this.radius.setMask(this.game.gameMask_mc);
  236.             this._canBePlaced = false;
  237.             ┬º┬ºpush(this.gotoAndStop("Red"));
  238.          }
  239.       }
  240.       else if(!this._drag && !this._enemyDetected)
  241.       {
  242.          var _loc2_ = 1;
  243.          while(_loc2_ <= this.game._enemyNumber)
  244.          {
  245.             if(this.game["Enemy" + _loc2_] != undefined && !this.game["Enemy" + _loc2_]._killed)
  246.             {
  247.                var _loc4_ = this.game["Enemy" + _loc2_]._x;
  248.                var _loc3_ = this.game["Enemy" + _loc2_]._y;
  249.                var _loc5_ = new Object({_xCenter:_loc4_,_yCenter:_loc3_,_radius:15});
  250.                if(this.circlesColliding(this.rangeCircle,_loc5_))
  251.                {
  252.                   this._enemyDetected = true;
  253.                   this.shoot(_loc4_ - this._x,_loc3_ - this._y,this.game["Enemy" + _loc2_]);
  254.                }
  255.             }
  256.             if(this._enemyDetected)
  257.             {
  258.                return undefined;
  259.             }
  260.             _loc2_ = _loc2_ + 1;
  261.          }
  262.       }
  263.    }
  264.    function onMouseMove()
  265.    {
  266.       if(this._drag)
  267.       {
  268.          setProperty(this, _X, this._parent._xmouse);
  269.          setProperty(this, _Y, this._parent._ymouse);
  270.          updateAfterEvent();
  271.       }
  272.    }
  273.    function onRollOver()
  274.    {
  275.       if(!this._drag && !this._SellUpgrade)
  276.       {
  277.          var _loc3_ = undefined;
  278.          var _loc2_ = this.game.interface_mc;
  279.          if(this.game._SellUpgrade)
  280.          {
  281.             _loc3_ = this.game.textMessages._weaponOptions;
  282.          }
  283.          else
  284.          {
  285.             _loc3_ = this.game.textMessages._weaponOver;
  286.          }
  287.          _loc2_.setText(_loc2_.info_txt,this._info);
  288.          _loc2_.setText(_loc2_.info2_txt,_loc3_);
  289.       }
  290.    }
  291.    function onRollOut()
  292.    {
  293.       if(!this._drag && !this._SellUpgrade)
  294.       {
  295.          this.game.interface_mc.setText(this.game.interface_mc.info_txt,"");
  296.          this.game.interface_mc.setText(this.game.interface_mc.info2_txt,"");
  297.       }
  298.    }
  299.    function onRelease()
  300.    {
  301.       if(this.game._stopped)
  302.       {
  303.          return undefined;
  304.       }
  305.       if(!this._drag)
  306.       {
  307.          var _loc2_ = this.game.interface_mc;
  308.          if(!this.radius._visible)
  309.          {
  310.             if(this.game.currentWeapon != undefined)
  311.             {
  312.                _loc2_.closeWeaponOptions(this.game.currentWeapon);
  313.             }
  314.             this.w_mc.gotoAndPlay("play");
  315.             this.game.currentWeapon = this;
  316.             this.game._SellUpgrade = true;
  317.             var _loc3_ = this.game.textMessages._weaponOptions;
  318.             _loc2_.setText(_loc2_.info2_txt,_loc3_);
  319.             _loc2_.attachWeaponOptions(this);
  320.             this.radius._visible = true;
  321.             this.swapDepths(this._parent.getNextHighestDepth());
  322.          }
  323.          else
  324.          {
  325.             _loc2_.closeWeaponOptions(this);
  326.          }
  327.       }
  328.       else
  329.       {
  330.          if(!this._canBePlaced)
  331.          {
  332.             return undefined;
  333.          }
  334.          if(this.weapon.hitTest(this.game.interface_mc))
  335.          {
  336.             this.game._draggingWeapon = false;
  337.             this.removeMovieClip();
  338.             return undefined;
  339.          }
  340.          if(!this.hitTest(this.game.interface_mc))
  341.          {
  342.          }
  343.          this._drag = this.game._draggingWeapon = false;
  344.          this.game.trail_mc.attachWeaponHitArea(this._x,this._y,this);
  345.          this.onMouseMove = undefined;
  346.          this.w_mc.numbers._visible = true;
  347.          this.game.interface_mc.addSubtractMoney(- this._value);
  348.          this.game.currentWeapon = undefined;
  349.          this.rangeCircle = new Object({_xCenter:this._x,_yCenter:this._y,_radius:this._range / 2});
  350.          this.radius._visible = false;
  351.       }
  352.    }
  353. }
  354.